home *** CD-ROM | disk | FTP | other *** search
- Path: news-m01.ny.us.ibm.net!usenet
- From: rwolf@ibm.net
- Newsgroups: comp.lang.c++,rb.technical
- Subject: Re: Can copy constructor and operator= share code?
- Date: 6 Mar 1996 04:19:37 GMT
- Organization: Rudolph Research
- Message-ID: <4hj3op$2ota@news-s01.ny.us.ibm.net>
- References: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM> <VA.00000053.00cdab05@fred> <4hdkdj$3id0@news-s01.ny.us.ibm.net> <4hhfa5$m6r@dawn.mmm.com>
- Reply-To: rwolf@ibm.net
- NNTP-Posting-Host: slip166-72-133-98.tx.us.ibm.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4hhfa5$m6r@dawn.mmm.com>, kjhopps@mmm.com (Kevin J Hopps) writes:
- >rwolf@ibm.net wrote:
- >> In <VA.00000053.00cdab05@fred>, Frederic LACHASSE
- >> <lachass@worldnet.fr> writes:
- >> >In article <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM>, borisb@sd.znet.com
- >> >(Boris Burtin) wrote:
- >> >>
- >> >> I have noticed that a copy constructor and operator= perform pretty
- >> >> much the same function. The code I wrote for my class simply copies
- >> >> each member variable from one class to the other.
- >> >>
- >
- >> A rather typical form is to have the create a "ShallowCopy"
- >> function that is called from both the copy constructor and the
- >> operator=. ShallowCopy copies only the member variables
- >> at the current derivation level.
- >
- >
- >The ShallowCopy function is not implemented here, but if it functions
- >as the name implies, a member which points to dynamically allocated
- >data would be copied by copying the pointer itself, not by creating a
- >new copy of the original pointed-to data. This creates a problem with
- >multiple deletion and dangling pointers as one of the copies is destroyed.
- >--
- Sorry for using my-own definition of shallow copy, but I did intent
- that dynamically allocated data is duplicated. My use of shallow refers
- to this derivation level.
-